//
//  NewFeatureController.m
//  Kugou-OC
//
//  Created by BH on 16/1/21.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "NewFeatureController.h"
#import "GlobalDefine.h"
#import <Masonry/Masonry.h>

#define IMAGE_COUNT 3

@interface NewFeatureController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation NewFeatureController

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    [NSThread sleepForTimeInterval:2.0];
    
    //添加scrollview
    [self addScrollview];
    
    //添加pageControl
    [self addPageControl];
}

/**
 *  添加scrollview
 */
-(void)addScrollview
{
    self.scrollview.contentSize = CGSizeMake(SCREEN_WIDTH * IMAGE_COUNT, SCREEN_HEIGHT);
    
    UIImageView *imageV1 = [[UIImageView alloc] init];
    imageV1.image = [UIImage imageNamed:@"newFeature1"];
    [self.scrollview addSubview:imageV1];
    
    UIImageView *imageV2 = [[UIImageView alloc] init];
    imageV2.image = [UIImage imageNamed:@"newFeature2"];
    [self.scrollview addSubview:imageV2];
    
    UIImageView *imageV3 = [[UIImageView alloc] init];
    imageV3.image = [UIImage imageNamed:@"newFeature3"];
    [self.scrollview addSubview:imageV3];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    tap.numberOfTapsRequired = 1;
    [imageV3 addGestureRecognizer:tap];
    
    [imageV1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.scrollview.mas_width);
        make.height.equalTo(self.scrollview.mas_height);
        make.left.top.equalTo(self.scrollview);
    }];
    
    [imageV2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageV1.mas_right);
        make.top.equalTo(self.scrollview);
        make.width.equalTo(self.scrollview.mas_width);
        make.height.equalTo(self.scrollview.mas_height);
    }];
    
    [imageV3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.scrollview.mas_width);
        make.height.equalTo(self.scrollview.mas_height);
        make.left.equalTo(imageV2.mas_right);
        make.top.equalTo(self.scrollview);
    }];
}

/**
 *  第3张图片单击手势
 */
-(void)tapAction
{
    
}

/**
 *  添加pageControl
 */
-(void)addPageControl
{
    
}

#pragma mark - scrollview delegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    double ratio = scrollView.contentOffset.x / scrollView.frame.size.width;
    NSInteger pageNo = (NSInteger)(ratio+0.5);
    self.pageControl.currentPage = pageNo;
}

@end
